package leetcode;

//Anagram: 由颠倒字母顺序构成的
public class ValidAnagram {

	public boolean isAnagram(String s, String t) {
		if(s == null || t == null){
            return s == t;
        }
		if(s.length() <= 0 || t.length() <= 0){
			return s.equals(t);
		}
		if(s.length() != t.length()){
			return false;
		}
		//存储出现的次数
		int[] sCount = new int[26];
		int[] tCount = new int[26];
		char[] sChars = s.toCharArray();
		char[] tChars = t.toCharArray();
		for (int i = 0; i < sChars.length; i++) {
			sCount[sChars[i] - 'a']++;
			tCount[tChars[i] - 'a']++;
		}
		for (int i = 0; i < sCount.length; i++) {
			if(sCount[i] != tCount[i]){
				return false;
			}
		}
		return true;
    }
}
